package org.yaac.shared.crud;

import java.io.Serializable;
import java.util.List;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
// TODO : meta property is not actually used in UI, deprecate this class?
public class MetaProperty implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * property name can be duplicated, however name + representation is always unique
	 */
	private String propertyName;
	
	private List<String> representation;

	/**
	 * used by GWT
	 */
	@SuppressWarnings("unused")
	private MetaProperty() {}
	
	/**
	 * @param propertyName
	 * @param representation
	 */
	public MetaProperty(String propertyName, List<String> representation) {
		super();
		this.propertyName = propertyName;
		this.representation = representation;
	}
	
	public String getPropertyName() {
		return propertyName;
	}

	public List<String> getRepresentation() {
		return representation;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((propertyName == null) ? 0 : propertyName.hashCode());
		result = prime * result + ((representation == null) ? 0 : representation.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MetaProperty other = (MetaProperty) obj;
		if (propertyName == null) {
			if (other.propertyName != null)
				return false;
		} else if (!propertyName.equals(other.propertyName))
			return false;
		if (representation == null) {
			if (other.representation != null)
				return false;
		} else if (!representation.equals(other.representation))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Property [propertyName=" + propertyName + ", representation=" + representation + "]";
	}
}